﻿<extend name="Public:base"/>
<block name="title">首页</block>
<block name="style">
<link rel="stylesheet" href="__CSS__/stylesheets/style.css">
<style>
.uploadify-bg{
	background-color:#fff;
	box-shadow:0px 0px 20px -2px rgba(0, 0, 0, 0.5);
}
#allfile{
	background: url(__CSS__/images/aside-hover-on.png) 0 -33px repeat-y;;
}
</style>
</block>
<block name="script">
<script src="__JS__/jquery-ui-1.8.17.custom.min.js"></script>
<script>
var username="";
$(document).ready(function(){ 
		$("#myplayer").css("display","none");
		$("#myplayer").mouseover(function(){
			$("#button").css("display","block");
			$("#close").css("display","block");
		});       
		$("#myplayer").mouseout(function(){
			$("#button").css("display","none");
			$("#close").css("display","none");
		}); 
		ajax('{:U("Index/files")}','json','',true,res.valuation);
		
});
    function ajax(_url, _dataType, _data, _sync, operation) {
        try {
            $.ajax({
                url: _url,
                type: "POST",
                dataType: _dataType,
                data: _data,
                async: _sync,
                error: function(msg) {
                    //tipsWindown("text*异常");    
                },
                success: function(data)
                {
                   //alert(data);
                    operation(data);


                }
            });
        } catch (error) {
            //tipsWindown("text*异常");
        }
    }
    var res={};
	var list=0;
	var fileinfo = [{    
					title: '',
					artist: '',
					album: '',
					cover: '',
					mp3: '',
					},
					];
    res.valuation=function(data){
		username = data[0].user_name;
		for (var i=0;i<data.length;i++){
		var file_size, create_time;
		if(data[i].file_size>=1024&&data[i].file_size<1048576){
			data[i].file_size=parseInt(data[i].file_size/1024);
			file_size=data[i].file_size+"KB";
		}
		else if(data[i].file_size>=1048576&&data[i].file_size<1073741824){
			data[i].file_size=parseInt(data[i].file_size/1048576);
			file_size=data[i].file_size+"MB";
		}
		else if(data[i].file_size>=1073741824){
			data[i].file_size=parseInt(data[i].file_size/1073741824);
			file_size=data[i].file_size+"GB";
		}
		else file_size=data[i].file_size+"B";
		/*数值转日期格式 */


	       // alert(data[i].create_time);
	       // alert(formatDate('Y-m-d H:i:s','1521963208'));
	      data[i].create_time = formatDate('Y-m-d H:i:s', data[i].create_time);




		var s='<tr onclick="checked('+i+')">';
		s+='<td width="2%"><input type="checkbox" name="items" id="check'+i+'"/><input type="hidden" id="file'+i+'" value="'+data[i].path +'"></td>';
		s+='<td width="70%" id="name'+i+'"><a href=javascript:preview("'+data[i].path+'","'+data[i].user_name+'","'+data[i].file_name.replace(/[ ]/g,"")+'") style="color:#000">'+data[i].file_name+'</a></td>';
		s+='<td width="13%"> '+file_size+'</td>';
		s+='<td width="15%"> '+data[i].create_time+'</td></tr>';
		$("#filelist").append(s);
		}
	}
	
	function checked(i){
		var inputs=document.getElementsByName("items");
		var checked_counts = 0;  
		$("#allcheked").attr("checked",false);
        if ($("#check"+i).attr("checked")) {
        	$("#check"+i).attr("checked", false);
			for(var n=0;n<inputs.length;n++){
			if(inputs[n].checked){
			checked_counts++;
			}
			}
			if(checked_counts==0){
				$("#select").html("文件夹");
			}else{
				$("#select").html("已选中<span>" + checked_counts + "</span>个文件/文件夹&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='share()'>分享</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='download()'>下载</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='del()'>删除</button>");
			}
        } else {  
            $("#check"+i).attr("checked", true);
			for(var n=0;n<inputs.length;n++){
			if(inputs[n].checked){
			checked_counts++;
			}
			}
			$("#select").html("已选中<span>" + checked_counts + "</span>个文件/文件夹&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='share()'>分享</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='download()'>下载</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='del()'>删除</button>");
		}
	}
	
	function checkall(){
		if ($("#allcheked").attr("checked")) {
			$("input[name=items]").each(function() {  
                $(this).attr("checked", true);
				$("#select").html("已选中所有文件/文件夹&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='share();init()'>分享</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='download()'>下载</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class='pure-button pure-button-small' onclick='del()'>删除</button>");
            });  		
		}else {  
            $("input[name=items]").each(function() {  
                $(this).attr("checked", false);  
				$("#select").html("文件夹");
            });  
        }  	
	}
	
	function del(){
		var inputs=document.getElementsByName("items");
		var checked_counts = 0; 
		var save_name = "";
		for(var n=0;n<inputs.length;n++){
			if(inputs[n].checked){
			checked_counts++;
			save_name += $("#file"+n).val()+",";
			}
			}
		//alert(save_name);
			if(confirm("您确认要删除该文件吗？")){        
				$.get('{:U("Uploadify/del")}', {file_name: save_name}, function() {
				//alert("删除成功！");
				location.reload();});
			}else{
				return false;
			}
	}
	
	function download(){
		//alert(document.getElementById("uer_name"));
		var inputs=document.getElementsByName("items");
		//var username=document.getElementById("uer_name").value;
		var checked_counts = 0; 
		var save_name = "";
		var singleFile = "";
		var nike_name ="";
		for(var n=0;n<inputs.length;n++){
			if(inputs[n].checked){
			checked_counts++;
			singleFile += $("#file"+n).val();
			nike_name += $("#name"+n).text();
			save_name += $("#file"+n).val()+",";
			}
			}
		if(checked_counts>1){
			$.get('{:U("Download/download")}', {file_name: save_name}, function() {
				window.location.href="__ROOT__/Uploads/"+username+"/package.zip";			
        });
		}
		else{
			var url="__ROOT__/"+ singleFile;
			window.location.href="__TMPL__/download/file.php?url="+url+"&nikename="+nike_name;			
		}
	}
	
	function share(){
		//alert(document.getElementById("uer_name"));
		var inputs=document.getElementsByName("items");
		//var username=document.getElementById("uer_name").value;
		var checked_counts = 0; 
		var save_name = "";
		var singleFile = "";
		var nike_name ="";
		for(var n=0;n<inputs.length;n++){
			if(inputs[n].checked){
			checked_counts++;
			singleFile += $("#file"+n).val();
			nike_name += $("#name"+n).text();
			save_name += $("#file"+n).val()+",";
			}
			}
		if(checked_counts>1){
			$.get('{:U("Download/download")}', {file_name: save_name}, function() {
				$('.modal-body').html("<div style='width:700px;margin:auto'>已生成下载链接，复制链接发送到QQ、MSN等好友<div style='margin:5px auto'>下载地址：<input class='shareUrl' type='text' value='http://localhost/index.php/Share/index.html?method=1&user="+username+"' size='80'/><button id='copy' class='pure-button pure-button-small' style='margin-left:10px;' onclick='copy()'>复制</button></div> </div>") 
				$('#preview').modal();			
        });
		}
		else{
		    nike=encodeURI(nike_name);//解决IE下URL传值乱码问题  
			$('.modal-body').html("<div style='width:700px;margin:auto'>已生成下载链接，复制链接发送到QQ、MSN等好友<div style='margin:5px auto'>下载地址：<input id='shareUrl' type='text' value='http://localhost/index.php/Share/index.html?method=0&singleFile="+singleFile+"&user="+username+"&nike="+nike+"' size='80' /><button id='copy' class='pure-button pure-button-small' style='margin-left:10px;' onclick='copy()'>复制</button></div> </div>") 
			$('#preview').modal();			
		}		
	}
	
	function copy() {
		var input=document.getElementById("shareUrl");//input的ID值 
		input.select(); //选择对象 
		document.execCommand("Copy"); //执行浏览器复制命令
		alert("已复制到剪贴板"); 
	}
	 
	function preview(filepath,username,file_name){
		var infoarr = file_name.split("."); 
		var suffix = infoarr[infoarr.length-1];//文件后缀
		var musicname = infoarr[infoarr.length-2];//文件原始名称，不带后缀
		var savePath = filepath;//"/Public/Upload/"+username+"/"+filename;//文件存储路径
		if(suffix=="jpg"||suffix=="png"||suffix=="gif"||suffix=="jpeg"){
			$('.modal-body').html('<img src="__ROOT__'+savePath+'" width="100%"/>')
			$('#preview').modal();
		}
		else if(suffix=="txt"){
			//$('.modal-body').html('<iframe src="__ROOT__/file.php?url='+filePath width="100%"></firame>')
			$.get('{:U("Index/preview_text")}', {file_Path: savePath}, function(data) {
				$('.modal-body').html(data);
				$('#preview').modal();
			});
		//window.location.href="__TMPL__/preview_text/preview_text.php?file_Path="+filePath;			
		}
		else if(suffix=="zip"||suffix=="rar"){
			$.get('{:U("Index/preview_zip")}', {file_Path: savePath}, function(data) {
				$('.modal-body').html(data);
				$('#preview').modal();
			});
		}
		else if(suffix=="mp3"){
			$.get('{:U("Index/get_musicCover")}', {musicname: musicname}, function(data) {
				$('.modal-body').html(data);
				$('#preview').modal();				
				var info = data.split(",");
				alert(info);			
				var cover = info[0];
				var album = info[1];
				var artist = info[2];
				fileinfo.title = musicname;
				fileinfo.artist = artist;
				fileinfo.album = album;
				fileinfo.cover = cover;
				fileinfo.mp3 = savePath;
				$( "#music" ).click();
				$( "#button" ).click();					
			});
		}
		else{
			return;
		}
	}

	function closelist(){
		$("#close").hide();
		$("#button").hide();
		$("#myplayer").css("display","none");
	}
	$(function() {
	function runEffect() {
		var selectedEffect = "clip";
		var options = {};
		$( "#myplayer" ).toggle( selectedEffect, options, 500 );
	};
	$( "#button" ).click(function() {
		if($(this).html()=="↑"){
		$(this).html("↓");
		}else{
		$(this).html("↑");
		}
		runEffect();
		return false;
	});
});
    /*日期格式转换*/
     function formatDate(format, timestamp){   
        var a, jsdate=((timestamp) ? new Date(timestamp*1000) : new Date());  
        var pad = function(n, c){  
            if((n = n + "").length < c){  
                return new Array(++c - n.length).join("0") + n;  
            } else {  
                return n;  
            }  
        };  
        var txt_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];  
        var txt_ordin = {1:"st", 2:"nd", 3:"rd", 21:"st", 22:"nd", 23:"rd", 31:"st"};  
        var txt_months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];   
        var f = {  
            // Day  
            d: function(){return pad(f.j(), 2)},  
            D: function(){return f.l().substr(0,3)},  
            j: function(){return jsdate.getDate()},  
            l: function(){return txt_weekdays[f.w()]},  
            N: function(){return f.w() + 1},  
            S: function(){return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th'},  
            w: function(){return jsdate.getDay()},  
            z: function(){return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0},  
            
            // Week  
            W: function(){  
                var a = f.z(), b = 364 + f.L() - a;  
                var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;  
                if(b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){  
                    return 1;  
                } else{  
                    if(a <= 2 && nd >= 4 && a >= (6 - nd)){  
                        nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");  
                        return date("W", Math.round(nd2.getTime()/1000));  
                    } else{  
                        return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);  
                    }  
                }  
            },  
            
            // Month  
            F: function(){return txt_months[f.n()]},  
            m: function(){return pad(f.n(), 2)},  
            M: function(){return f.F().substr(0,3)},  
            n: function(){return jsdate.getMonth() + 1},  
            t: function(){  
                var n;  
                if( (n = jsdate.getMonth() + 1) == 2 ){  
                    return 28 + f.L();  
                } else{  
                    if( n & 1 && n < 8 || !(n & 1) && n > 7 ){  
                        return 31;  
                    } else{  
                        return 30;  
                    }  
                }  
            },  
            
            // Year  
            L: function(){var y = f.Y();return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0},  
            //o not supported yet  
            Y: function(){return jsdate.getFullYear()},  
            y: function(){return (jsdate.getFullYear() + "").slice(2)},  
            
            // Time  
            a: function(){return jsdate.getHours() > 11 ? "pm" : "am"},  
            A: function(){return f.a().toUpperCase()},  
            B: function(){  
                // peter paul koch:  
                var off = (jsdate.getTimezoneOffset() + 60)*60;  
                var theSeconds = (jsdate.getHours() * 3600) + (jsdate.getMinutes() * 60) + jsdate.getSeconds() + off;  
                var beat = Math.floor(theSeconds/86.4);  
                if (beat > 1000) beat -= 1000;  
                if (beat < 0) beat += 1000;  
                if ((String(beat)).length == 1) beat = "00"+beat;  
                if ((String(beat)).length == 2) beat = "0"+beat;  
                return beat;  
            },  
            g: function(){return jsdate.getHours() % 12 || 12},  
            G: function(){return jsdate.getHours()},  
            h: function(){return pad(f.g(), 2)},  
            H: function(){return pad(jsdate.getHours(), 2)},  
            i: function(){return pad(jsdate.getMinutes(), 2)},  
            s: function(){return pad(jsdate.getSeconds(), 2)},  
            //u not supported yet  
            
            // Timezone  
            //e not supported yet  
            //I not supported yet  
            O: function(){  
                var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);  
                if (jsdate.getTimezoneOffset() > 0) t = "-" + t; else t = "+" + t;  
                return t;  
            },  
            P: function(){var O = f.O();return (O.substr(0, 3) + ":" + O.substr(3, 2))},  
            //T not supported yet  
            //Z not supported yet  
            
            // Full Date/Time  
            c: function(){return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P()},  
            //r not supported yet  
            U: function(){return Math.round(jsdate.getTime()/1000)}  
        };  
            
        return format.replace(/[\\]?([a-zA-Z])/g, function(t, s){  
            if( t!=s ){  
                // escaped  
                ret = s;  
            } else if( f[s] ){  
                // a date function exists  
                ret = f[s]();  
            } else{  
                // nothing special  
                ret = s;  
            }  
            return ret;  
        });  
    }  
    //test  
    //alert(formatDate('Y-m-d H:i:s',(new Date).getTime()/1000));  
    //alert(formatDate('Y-m-d',(new Date).getTime()/1000));  
     
</script>
</block>
<block name="content">


<!--fileList table begin-->    
    <table class="table table-hover">
        <tbody id="filelist" style="height:50%; overflow:auto">
    
        </tbody>
    </table>
    <button class="pure-button pure-button-secondary pure-button-xsmall" id="music" onclick="music()" style="display:none"></button>

<!--fileList table end-->
    
<!--music player begin-->
<div id="myplayer">   
	<!--<div id="background"></div>-->
	<div id="player">
		<div class="cover"></div>
		<div class="ctrl">
			<div class="tag">
				<strong>Title</strong>
				<span class="artist">Artist</span>
				<span class="album">Album</span>
			</div>
			<div class="control">
				<div class="left">
					<div class="rewind icon"></div>
					<div class="playback icon"></div>
					<div class="fastforward icon"></div>
				</div>
				<div class="volume right">
					<div class="mute icon left"></div>
					<div class="slider left">
						<div class="pace"></div>
					</div>
				</div>
			</div>
			<div class="schedule">
				<div class="slider">
					<div class="loaded"></div>
					<div class="pace"></div>
				</div>
				<div class="timer left">0:00</div>
				<div class="right">
					<div class="repeat icon"></div>
					<div class="shuffle icon"></div>
				</div>
			</div>
		</div>
	</div>
	<ul id="playlist"></ul>
    <button class="pure-button pure-button-secondary pure-button-xsmall" id="button" style="position:absolute; top:30px; right:-50px; display: none">↑</button>
    <button class="pure-button pure-button-secondary pure-button-xsmall" id="close" onclick="closelist()" style="position: absolute; top:0px; right:-50px;display:none">×</button> 
    <script src="/Static/js/script.js"></script>
    </div>
<!--music player end-->    
</block>